﻿using Funq;

namespace BlackJack.Infrastructure.IoC
{
    public class ContainerLocator
    {
        #region Members

        Container _container;

        #endregion

        #region Singleton

        static ContainerLocator _instance;

        public static ContainerLocator Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new ContainerLocator();

                return _instance;
            }
        }

        #endregion

        #region Constructor

        ContainerLocator()
        {
            _container = new Container();
        }

        #endregion

        #region Public Methods

        public void Register<TFrom, TTo>()
            where TTo : TFrom
        {
            _container.Register(c => c.Resolve<TTo>());
        }

        public T Resolve<T>()
        {
            return _container.Resolve<T>();
        }

        #endregion
    }
}
